home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / libdwarf / dwarf_util.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.0 KB  |  167 lines

  1. /*
  2.     dwarf_util.h
  3.  
  4.     $Revision: 1.15 $        $Date: 1993/09/30 17:03:01 $
  5. */
  6. #include <limits.h>
  7.  
  8. /*
  9.     Decodes unsigned leb128 encoded numbers that 
  10.     are assumed to be less than 4 bytes long.  
  11.     Make sure ptr is a pointer to a 1-byte type.  
  12.     Returns UINT_MAX on error.
  13.  
  14.     Limits.h is included to define UINT_MAX.
  15. */
  16. #define DECODE_LEB128_UWORD(ptr, value) \
  17.     { \
  18.         Dwarf_Small    byte; \
  19.     \
  20.         value = (byte = *(ptr++)) & 0x7f; \
  21.         if ((byte & 0x80) != 0) { \
  22.         value |= ((byte = *(ptr++)) & 0x7f) << 7; \
  23.         if ((byte & 0x80) != 0) { \
  24.             value |= ((byte = *(ptr++)) & 0x7f) << 14; \
  25.             if ((byte & 0x80) != 0) { \
  26.             value |= ((byte = *(ptr++)) & 0x7f) << 21; \
  27.             if ((byte & 0x80) != 0) { \
  28.                 value = UINT_MAX; \
  29.             } \
  30.             } \
  31.         } \
  32.         } \
  33.     }
  34.  
  35. /*
  36.     Decodes signed leb128 encoded numbers that
  37.     are assumed to be less than 4 bytes long.
  38.     Make sure ptr is a pointer to a 1-byte type.
  39.     Returns INT_MAX on error.
  40.  
  41.     Make sure value is a 4-byte signed int.
  42. */
  43. #define DECODE_LEB128_SWORD(ptr, value) \
  44.     { \
  45.     Dwarf_Small    byte; \
  46.     \
  47.     value = (byte = *(ptr++)) & 0x7f; \
  48.     if ((byte & 0x80) == 0) { \
  49.         if ((byte & 0x40) != 0)  \
  50.             value |= 0xffffff80; \
  51.     } \
  52.     else { \
  53.         value |= ((byte = *(ptr++)) & 0x7f) << 7; \
  54.         if ((byte & 0x80) == 0) { \
  55.         if ((byte & 0x40) != 0) \
  56.             value |= 0xffffc000; \
  57.         } \
  58.         else { \
  59.         value |= ((byte = *(ptr++)) & 0x7f) << 14; \
  60.         if ((byte & 0x80) == 0) { \
  61.             if ((byte & 0x40) != 0) \
  62.             value |= 0xffe00000; \
  63.         } \
  64.         else { \
  65.             value |= ((byte = *(ptr++)) & 0x7f) << 21; \
  66.             if ((byte & 0x80) == 0) { \
  67.             if ((byte & 0x40) != 0) \
  68.                 value |= 0xf0000000; \
  69.             } \
  70.             else  \
  71.             value = INT_MAX; \
  72.         } \
  73.         } \
  74.     } \
  75.     }
  76.  
  77.  
  78. /*
  79.     Skips leb128_encoded numbers that are guaranteed 
  80.     to be no more than 4 bytes long.  Same for both
  81.     signed and unsigned numbers.
  82. */
  83. #define SKIP_LEB128_WORD(ptr) \
  84.     if ((*(ptr++) & 0x80) != 0) { \
  85.         if ((*(ptr++) & 0x80) != 0) { \
  86.             if ((*(ptr++) & 0x80) != 0) { \
  87.             if ((*(ptr++) & 0x80) != 0) { \
  88.             } \
  89.         } \
  90.         } \
  91.     }
  92.  
  93.  
  94. #define CHECK_DIE(die, error_ret_value) \
  95.     if (die == NULL) { \
  96.     _dwarf_error(NULL, error, DW_DLE_DIE_NULL); \
  97.     return(error_ret_value); \
  98.     } \
  99.     if (die->di_cu_context == NULL) { \
  100.     _dwarf_error(NULL, error, DW_DLE_DIE_NO_CU_CONTEXT); \
  101.     return(error_ret_value); \
  102.     } \
  103.     if (die->di_cu_context->cc_dbg == NULL) { \
  104.     _dwarf_error(NULL, error, DW_DLE_DBG_NULL); \
  105.     return(error_ret_value); \
  106.     } 
  107.  
  108.  
  109. /* 
  110.     This macro copies length number of bytes from source to dest.  
  111.     The actual destination address is adjusted to account for the 
  112.     difference in the number of bytes in dest, and length.  
  113. */
  114. #define READ_UNALIGNED(dest, source, length) \
  115.     dest = 0; \
  116.     if (length > sizeof(dest)) \
  117.     memcpy(&dest, (char *)source + length - sizeof(dest), sizeof(dest)); \
  118.     else \
  119.         memcpy((char *)&dest + sizeof(dest) - length, source, length) 
  120.  
  121.  
  122. /*
  123.     This macro sign-extends a variable depending on the length.
  124.     It fills the bytes between the size of the destination and
  125.     the length with appropriate padding.
  126. */
  127. #define SIGN_EXTEND(dest, length) \
  128.     if (*(Dwarf_Sbyte *)((char *)&dest + sizeof(dest) - length) < 0) \
  129.     memcpy((char *)&dest, "\xff\xff\xff\xff\xff\xff\xff\xff", \
  130.         sizeof(dest) - length)
  131.  
  132.  
  133. Dwarf_Unsigned
  134. _dwarf_decode_u_leb128 (
  135.     Dwarf_Small         *leb128,
  136.     Dwarf_Word          *leb128_length
  137. );
  138.  
  139. Dwarf_Signed 
  140. _dwarf_decode_s_leb128 (
  141.     Dwarf_Small     *leb128, 
  142.     Dwarf_Word         *leb128_length
  143. );
  144.  
  145. Dwarf_Unsigned 
  146. _dwarf_get_size_of_val (
  147.     Dwarf_Debug        dbg,
  148.     Dwarf_Unsigned      form,
  149.     Dwarf_Small         *val_ptr
  150. );
  151.  
  152. /*
  153.     This struct is used to build a hash table for the
  154.     abbreviation codes for a compile-unit.  
  155. */
  156. struct Dwarf_Hash_Table_s {
  157.     Dwarf_Abbrev_List    at_head;
  158.     Dwarf_Abbrev_List    at_tail;
  159. };
  160.  
  161. Dwarf_Abbrev_List
  162. _dwarf_get_abbrev_for_code (
  163.     Dwarf_CU_Context    cu_context,
  164.     Dwarf_Word          code
  165. );
  166.  
  167.